package com.springapi.dao;

import com.springapi.entity.Mailreport;
import com.springapi.entity.Mailreporttwo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.data.domain.Pageable;
import java.util.List;

/**
 * 系统设置(Mailreporttwo)表数据库访问层
 *
 * @author makejava
 * @since 2025-02-26 15:27:16
 */
public interface MailreporttwoDao {



    /**
     * 通过appid和shopid查询年月日周数据
     */
    @Select("SELECT 1 as id,     SUM(CASE WHEN YEARWEEK(intime) = YEARWEEK(CURDATE()) THEN 1 ELSE 0 END) AS value1,     SUM(CASE WHEN YEARWEEK(intime) = YEARWEEK(CURDATE()) - 1 THEN 1 ELSE 0 END) AS value2,     SUM(CASE WHEN DATE(intime) = CURDATE() THEN 1 ELSE 0 END) AS value3,     SUM(CASE WHEN DATE(intime) = CURDATE() - INTERVAL 1 DAY THEN 1 ELSE 0 END) AS value4,     SUM(CASE WHEN YEAR(intime) = YEAR(CURDATE()) AND MONTH(intime) = MONTH(CURDATE()) THEN 1 ELSE 0 END) AS value5,     SUM(CASE WHEN YEAR(intime) = YEAR(CURDATE()) AND MONTH(intime) = MONTH(CURDATE()) - 1 THEN 1 ELSE 0 END) AS value6 FROM     maillist \t\twhere appid=#{appid} \t\tand shopid=#{shopid} \t\tUNION \tSELECT 2  id,     '本周'  value1,     '上周' value2,     '今日' value3,     '昨日' value4,     '本月' value5,     '上月' value6 FROM     maillist ")
    List<Mailreporttwo> findmailreport2(@Param("appid") int appid, @Param("shopid") int shopid );

    /**
     * 通过appid和shopid 统计各家快递公司上个月包裹数
     */
    @Select("SELECT 0 as id,     delivery as value1,     COUNT(*) AS value2 FROM     maillist  WHERE     YEAR(intime) = YEAR(CURRENT_DATE - INTERVAL 1 MONTH)     AND MONTH(intime) = MONTH(CURRENT_DATE - INTERVAL 1 MONTH) \t\tand appid=#{appid}  and shopid=#{shopid} GROUP BY     delivery ")
    List<Mailreporttwo> findlastmonthdelivery(@Param("appid") int appid, @Param("shopid") int shopid );

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    Mailreporttwo queryById(Integer id);

    /**
     * 查询指定行数据
     *
     * @param mailreporttwo 查询条件
     * @param pageable         分页对象
     * @return 对象列表
     */
    List<Mailreporttwo> queryAllByLimit(Mailreporttwo mailreporttwo, @Param("pageable") Pageable pageable);

    /**
     * 统计总行数
     *
     * @param mailreporttwo 查询条件
     * @return 总行数
     */
    long count(Mailreporttwo mailreporttwo);

    /**
     * 新增数据
     *
     * @param mailreporttwo 实例对象
     * @return 影响行数
     */
    int insert(Mailreporttwo mailreporttwo);

    /**
     * 批量新增数据（MyBatis原生foreach方法）
     *
     * @param entities List<Mailreporttwo> 实例对象列表
     * @return 影响行数
     */
    int insertBatch(@Param("entities") List<Mailreporttwo> entities);

    /**
     * 批量新增或按主键更新数据（MyBatis原生foreach方法）
     *
     * @param entities List<Mailreporttwo> 实例对象列表
     * @return 影响行数
     * @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常，请自行校验入参
     */
    int insertOrUpdateBatch(@Param("entities") List<Mailreporttwo> entities);

    /**
     * 修改数据
     *
     * @param mailreporttwo 实例对象
     * @return 影响行数
     */
    int update(Mailreporttwo mailreporttwo);

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 影响行数
     */
    int deleteById(Integer id);

}

